<template>
	<view class="orders" :class="[this.roleClass]">
		<view class="store-info">
			<view class="flex-left">
				<view class="store-icon"></view>
				<view class="store-name">店铺名称: {{statsData.site_name}}</view>
			</view>
			<!-- <view class="store-head">负责人：{{statsData.website_name}}</view> -->
		</view>
		<view class="month-picker" @click="showMonthPicker">
			<view class="month-value">{{period[0]}}年{{period[1]}}月</view>
			<view class="arrow-down"></view>
		</view>
		<view class="stats">
			<view class="stats-item" v-for="(item,index) in stats" :key="index">
				<view class="stats-title">{{item.title}}</view>
				<view class="stats-value">{{statsData[item.index] || 0}}</view>
			</view>
		</view>
		<view class="charts">
			<uCharts v-if="serverData.opts" :scroll="serverData.enableScroll" :show="canvas" :canvasId="serverData.id"
				:chartType="serverData.chartType" :extraType="serverData.extraType" :cWidth="cWidth" :cHeight="cHeight"
				:opts="serverData.opts" ref="order_total" />
		</view>
		<view class="list">
			<view class="list-nav"  v-if="role == 'merchant'">
				<view class="list-nav-item" :class="{active:listNavValue === item.value}"
					v-for="(item,index) in listNav" @click="turnListNav(item.value)">
					{{item.title}}
				</view>
			</view>
			<view class="orders-list">
				<view class="order" v-if="list.length > 0" v-for="(item,index) in list" :key="index">
					<view class="order-sn">订单号：{{item.order_no || item.collection_no}}</view>
					<view class="order-product" v-if="item.order_goods_id">
						<image class="product-image" :src="item.sku_image" mode="scaleToFill"></image>
						<view class="product-rest">
							<view class="product-info">
								<view class="product-name">{{item.sku_name}}</view>
								<view class="">
									<!-- <view class="product-price">{{item.price}}</view> -->
									<view class="product-num">x{{item.num}}</view>
								</view>
							</view>
							<view class="order-amount">合计<view class="order-amount-value">¥{{item.price}}</view>
							</view>
						</view>
					</view>
					<view class="order-between">
						<view class="order--title">订单总额</view>
						<view class="order-value">¥{{item.total_money || item.money}}</view>
					</view>
					<view class="order-between">
						<view class="order--title">奖励消费券</view>
						<view class="order-value" style="color: #FF4544;">{{item.commission}}</view>
					</view>
					<view class="order-between">
						<view class="order--title">订单状态</view>
						<view class="order-value">{{item.order_status_name || '已完成'}}</view>
					</view>
					<view class="order-between">
						<view class="order--title">下单时间</view>
						<view class="order-value">{{item.create_time}}</view>
					</view>
				</view>
				<ns-empty v-if="!list.length" text="暂无订单信息" :fixed="!1" :isIndex="!1"></ns-empty>
			</view>
		</view>
		<month-picker ref="monthPicker" @onConfirm="confirmMonth"></month-picker>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	import uCharts from './components/u-charts/u-charts.vue';
	import monthPicker from './components/diy-month-picker/diy-month-picker.vue';
	import ordersDataCharts from './js/ordersDataCharts.js';
	export default {
		components: {
			monthPicker,
			uCharts
		},
		mixins: [ordersDataCharts],
		data() {
			return {
				id: '',
				role: '',
				roleClass: '',
				period: {
					year: {},
					month: {}
				},
				stats: [],
				merchantStats: [{
					title: '线上订单量',
					index: 'onlineCount'
				},{
					title: '线上交易额(元)',
					index: 'onlineMoneySum'
				},{
					title: '线上奖励消费券',
					index: 'onlineCommission'
				},{
					title: '线下订单量',
					index: 'offlineCount'
				}, {
					title: '线下交易额(元)',
					index: 'offlineMoneySum'
				},{
					title: '线下奖励消费券',
					index: 'offlineCommission'
				}],
				statsData: {},
				list: [],
				page: 1,
				page_size: 10,
				page_count: 1,
				listNav: [{
					title: '线上订单',
					value: '1'
				}, {
					title: '线下订单',
					value: '2'
				}],
				listNavValue: '1'
			};
		},
		computed: {

		},
		onLoad(options) {
			this.role = options.role;
			this.id = options.id;
			let title = '商家数据';
			this.stats = this.merchantStats;
			uni.setNavigationBarTitle({
				title
			});
			// 初始化时间
			let today = new Date();
			let year = today.getFullYear();
			let month = today.getMonth() + 1;
			this.period = [year, month];
			this.getorderHead();
			this.getorderList();
		},
		methods: {
			turnListNav(value) {
				this.listNavValue = value;
				this.page = 1;
				this.list = [];
				this.getorderList();
			},
			showMonthPicker() {
				this.$refs.monthPicker.show()
			},
			confirmMonth(data) {
				this.period = data.split('-');
				this.list = [];
				this.getorderHead();
				this.getorderList();
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '../common/css/mixins.scss';
	$imgBusinessPath:'business/';

	@mixin box {
		width: 690rpx;
		background-color: #fff;
		border-radius: 8rpx;
	}

	.orders {
		padding: 30rpx;
		background-image: linear-gradient(180deg, #FFEADB 0%, #F8F8F8 100%);
		background-size: 100% 580rpx;
		background-repeat: no-repeat;

		&.teamleader {
			background-image: linear-gradient(180deg, #FFEDED 0%, #F8F8F8 100%);
		}

		&.promoters {

			background-image: linear-gradient(180deg, #E5FAF6 0%, #F8F8F8 100%);
		}
	}

	.store-info {
		@include flex(space-between);
		margin-bottom: 40rpx;

		.store-icon {
			@include image('icon-store.png');
			width: 40rpx;
			height: 40rpx;
			margin-right: 8rpx;
		}

		.store-name,
		.store-head {
			font-size: 32rpx;
			color: #000000;
			line-height: 45rpx;
		}
	}

	.month-picker {
		@include flex(space-between);
		@include box;
		padding: 0 50rpx;
		height: 88rpx;

		.month-value {
			font-size: 32rpx;
			color: #303133;
			line-height: 45rpx;
		}

		.arrow-down {
			@include image('arrow-fill-down.png');
			width: 28rpx;
			height: 28rpx;
		}
	}

	.stats {
		// @include flex(space-between);
		margin-top: 24rpx;
		padding: 30rpx 0 20rpx 0;
		@include box;
		// height: 174rpx;
		overflow: hidden;

		.stats-item {
			float: left;
			width: 33.33333%;
			@include flex;
			flex-direction: column;

			.stats-title {
				font-size: 24rpx;
				color: #909399;
				line-height: 33rpx;
			}

			.stats-value {
				font-size: 48rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FF4544;
				line-height: 67rpx;
			}
		}
	}

	.flex-left {
		@include flex(flex-start);
	}

	.charts {
		@include box;
		margin-top: 24rpx;
		width: 690rpx;
		height: 590rpx;
	}


	.list {
		margin-top: 24rpx;

		.list-nav {
			@include flex(space-between);
			background-color: #fff;
			height: 90rpx;

			.list-nav-item {
				width: 50%;
				height: 100%;
				@include flex;
				font-size: 28rpx;
				color: #303133;
				line-height: 40rpx;

				&.active {
					position: relative;
					color: #FF4544;

					&::after {
						content: '';
						position: absolute;
						bottom: 0;
						width: 60rpx;
						height: 4rpx;
						background: #FF4544;

					}
				}
			}
		}

		.orders-list {
			.order {
				@include box;
				margin-top: 24rpx;
				padding: 30rpx;

				.order-sn {
					font-size: 28rpx;
					color: #000000;
					line-height: 40rpx;
					margin-bottom: 20rpx;
				}

				.order-product {
					@include flex(flex-start);
					margin-bottom: 20rpx;

					.product-image {
						width: 160rpx;
						height: 160rpx;
						flex-shrink: 0;
					}

					.product-rest {
						margin-left: 20rpx;
						flex-grow: 2;
					}

					.product-info {
						@include flex(space-between);

						.product-name {
							width: 338rpx;
							height: 80rpx;
							font-size: 28rpx;
							color: #303133;
							line-height: 40rpx;
						}

						.product-price {
							font-size: 28rpx;
							color: #303133;
							line-height: 28rpx;

							&::before {
								content: '¥';
								font-size: 20rpx;
							}
						}

						.product-num {
							font-size: 24rpx;
							color: #909399;
							line-height: 24rpx;
						}
					}

					.order-amount {
						margin-top: 30rpx;
						font-size: 24rpx;
						color: #909399;
						line-height: 34rpx;
						@include flex(flex-end);

						.order-amount-value {
							margin-left: 8rpx;
							color: #FF4544;
						}
					}

				}
				
				.order-between {
					@include flex(space-between);
				}
			}
		}
	}
</style>
